/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.POSBeerView;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "posProductServingType")
@XmlRootElement
public class POSProductServingType implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "servingTypeID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "cost")
    private float stCost;
    @JoinColumn(name = "glassWareType", referencedColumnName = "glassWareID", nullable=false)
    @ManyToOne(optional = false)
    private POSGlassWare glassware;
    @JoinColumn(name = "stBeer", referencedColumnName = "BId", nullable=true)
    @ManyToOne(optional = true)
    private POSBeerView servingTypeBeer;
    @OneToMany(mappedBy = "product")
    private Collection<POSLineItems> lineItemCollection;

    public POSProductServingType() {
    }

    public POSProductServingType(Integer id) {
        this.id = id;
    }

    public POSProductServingType(Integer id, float stCost) {
        this.id = id;
        this.stCost = stCost;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public float getStCost() {
        return stCost;
    }

    public void setStCost(float stCost) {
        this.stCost = stCost;
    }

    public POSGlassWare getGlassware() {
        return glassware;
    }

    public void setGlassware(POSGlassWare glassware) {
        this.glassware = glassware;
    }

    public POSBeerView getServingTypeBeer() {
        return servingTypeBeer;
    }

    public void setServingTypeBeer(POSBeerView servingTypeBeer) {
        if(servingTypeBeer != null && servingTypeBeer.getbId()!=null){
            this.servingTypeBeer = servingTypeBeer;
        }
    }

    @XmlTransient
    public Collection<POSLineItems> getLineItemCollection() {
        return lineItemCollection;
    }

    public void setLineItemCollection(Collection<POSLineItems> lineItemCollection) {
        this.lineItemCollection = lineItemCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSProductServingType)) {
            return false;
        }
        POSProductServingType other = (POSProductServingType) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.posproductservingtype[ id=" + id + " ]";
    }
}
